<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            background-color: #bbb;
        }

        #canvas {
            background-color: pink;
        }
    </style>
</head>

<body>
    <canvas id="canvas" width="400" height="400"></canvas>
    <textarea name="" id="log" cols="30" rows="10"></textarea>
</body>
<script src="./utils.js"></script>
<script src="./arrow.js"></script>
<script src="./ball.js"></script>
<script src="./ship.js"></script>
<script>
    window.onload = () => {
        var canvas = document.getElementById("canvas");
        var context = canvas.getContext("2d");
        var log = document.getElementById("log"),
            mouse = utils.captureMouse(canvas),
            ball = new Ball(),
            spring = 0.03,
            gravity = 2,
            vx = 0,
            vy = 0,
            friction = 0.95;

        (function drawFrame() {
            window.requestAnimationFrame(drawFrame, canvas)
            context.clearRect(0, 0, canvas.width, canvas.height)

            var dx = mouse.x - ball.x,
                dy = mouse.y - ball.y,
                ax = dx * spring,
                ay = dy * spring;

            vx += ax;
            vy += ay;
            vx *= friction;
            vy *= friction;
            ball.x += vx;
            ball.y += vy;

            context.beginPath();
            context.moveTo(ball.x,ball.y)
            context.lineTo(mouse.x,mouse.y)
            context.stroke()

            ball.draw(context)
        }())
    };
</script>

</html>